<?php

namespace app\common\model;

use think\Model;
use think\Db;

class Admin extends Model
{
    public function login($data)
    {
        
        if (!captcha_check($data['vercode'])) {
            return ['code' => 0, 'msg' => '验证码错误'];
        }
        $user = Db::name('admin')->where('username', $data['username'])->find();
        if ($user) {
            if ($user['status'] == 1 && $user['password'] == md5($data['password'])) {
                session('username', $user['username']);
                session('admin_id', $user['id']);
                $avatar = $user['avatar'] == '' ? '__PUBLIC__admin/images/0.jpg' : $user['avatar'];
                session('avatar', $avatar);
                return ['code' => 1, 'msg' => '登录成功!']; //信息正确
            } else {
                return ['code' => 0, 'msg' => '用户名或者密码错误，重新输入!']; //密码错误
            }
        } else {
            return ['code' => 0, 'msg' => '用户不存在!']; //用户不存在
        }
    }
    
    public function getInfo($admin_id)
    {
        $info = Db::name('admin')->field('pwd', true)->find($admin_id);
        return $info;
    }
    
}